Declare Function midiOutOpen Lib "mmsystem" (handle As Integer, ByVal id As Integer, ByVal callback As Long, ByVal dwinstance As Long, ByVal flags As Long) As Integer
Declare Sub midiOutClose Lib "mmsystem" (ByVal handle As Integer)
Declare Function midiOutShortMsg Lib "mmsystem" (ByVal handle As Integer, ByVal message As Long) As Long
Global hMidi As Integer
Global istatus As Integer
Global ichannel As Integer
Global idata1 As Integer
Global ldata2 As Long
Global lmessage As Long
' Listing 2
Sub Form_Load ()
' Try to open the default MIDI device.
ErrCode = midiOutOpen(hmidi, -1, 0, 0, 0)
' Quit w/error if unable to.
If ErrCode <> 0 Then
st$ = "Error code " + Str$(ErrCode)
MsgBox (st$) ', 16, "Error!")
End
Else
' Send the patch change
' for voice 25, the steel-
' string guitar in General MIDI.
lmessage = &HC0 Or 0 Or (25 * 256) Or (0 * 65536)
ic& = midiOutShortMsg(hmidi, lmessage)
End If
' Set default values in the text boxes.
' This is the Note On message.
text1.text = "&h90"
' This value isn't used for note on.
text2.text = "0"
' Middle C.
text3.text = "64"
' Maximum volume.
text4.text = "127"
End Sub
' Listing 3
Sub Form_Unload (Cancel As Integer)
' Close the MIDI device. This must be
' done; otherwise it can't be used until
' Windows is restarted.
Call midiOutClose(hmidi)
End Sub
' Listing 4
Sub Command1_Click ()
' The 3 bytes of a MIDI message must be written to lmessage.
lmessage = istatus Or ichannel Or (idata1 * 256) Or (ldata2 * 65536)